#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
pthread_t main_thread;
void* routine(void* arg)
{
    char* msg=(char*)arg;
    int count=5;
    while(count--)
    {
        printf("%s\n",msg);
        pthread_cancel(main_thread);
        sleep(1);
    }
    return NULL;
}
int main(void)
{
    int n=5;
    main_thread=pthread_self();
    pthread_t tid[n];
    for(int i=0;i<n;i++)
    {

        char* buff=(char*)malloc(sizeof(char)*64);
        sprintf(buff,"thread[%d]:running...",i);
        pthread_create(&tid[i],NULL,routine,buff);
    }
    for(int i=0;i<n;i++)
    {
        pthread_join(tid[i],NULL);
        printf("Thread[%d] ... quit\n",i);
        
    }
    while(1);
    return 0;

}
